package com.jmpt.fangbohui.ui.holder;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jmpt.fangbohui.R;
import com.jmpt.fangbohui.bean.NewHouseDetailBean;
import com.jmpt.fangbohui.bean.NewHouseDetailBean.New;
import com.jmpt.fangbohui.ui.NewHouseDetailActivity;
import com.jmpt.fangbohui.ui.base.BaseViewHolder;

/*
 * 新房新闻
 */
public class NewListHolder extends BaseViewHolder<List<NewHouseDetailBean.New>> {
	
	LinearLayout rootView;
	
	public NewListHolder(Context context) {
		super(context);
	}

	@Override
	protected View initView() {
		rootView = (LinearLayout) View.inflate(mContext, R.layout.news_holder, null);
		
		return rootView;
	}

	@Override
	protected void refreshView(List<NewHouseDetailBean.New> data) {
		if(data == null || data.size() < 1){
			
			rootView.addView(View.inflate(mContext, R.layout.no_more, null));
			
			return;
		}
		/*for (int i = 0; i < data.size(); i++) {
			rootView.addView(getItem(data.get(i)));
		}*/
		
		for (int i = 0; i < data.size() && i < 5; i++) {
			rootView.addView(getItem(data.get(i)));
		}
		
		if(data.size() > 5){
			rootView.addView(getMoreView());
		}
	}

	private View getMoreView() {
		View view = View.inflate(mContext, R.layout.more_news, null);
		view.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO 更多
				((NewHouseDetailActivity)mContext).moreNews();
			}
		});
		return view;
	}

	private View getItem(New new1) {
		NewsItemHolder itemHolder = new NewsItemHolder(mContext);
		
		itemHolder.setData(new1);
		
		return itemHolder.getRootView();
	}

}
